'''
基于差异点做斯坦纳树
'''
import sys

import networkx as nx
import matplotlib.pyplot as plt

plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus']=False


from .metric_closure import metric_closure
from .mst_for_complete_graph import mst_for_complete_graph
from .the_unique_mst_inturn import the_unique_mst_inturn
from .the_unique_mst_overall import the_unique_mst_overall

from .st_1 import st_1
from .st_2 import st_2
from .st_3 import st_3
from .st_4 import st_4

from .removing_cycle import removing_cycle
from .deleting_un_nodes import deleting_un_nodes
from .map_to_originalGraph import map_to_originalGraph





def steinertree_nodes(itera_num ,gg,terminal_nodes):
    stEgdes = []
    for m in range(itera_num):
        M = metric_closure(gg, weight='weight')
        N = M.subgraph(terminal_nodes)
        NN, cost, re, constructG1 = mst_for_complete_graph(gg, N, terminal_nodes)
        constructG2 = the_unique_mst_inturn(NN, gg, re, cost, terminal_nodes)
        constructG3 = the_unique_mst_overall(NN, gg, re, cost, terminal_nodes)
        Glist = constructG1 + constructG2 + constructG3

        for i in Glist:  # 将所有的图依次进行去环
            gI = nx.Graph(i)  # 图形解冻
            gII = removing_cycle(gI)  # 去环
            gIII = deleting_un_nodes(gII, terminal_nodes)  # 删除非必要节点   最终的图

            stEgdes += gIII.edges()
    stEdges = list(set(stEgdes))

    return  stEgdes